import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

interface WithRouterProps {
}

const withRouter = <Props extends WithRouterProps>(Component: React.ComponentType<Props>) => {
    // eslint-disable-next-line react/display-name
    return (props: Props) => {
        const location = useLocation();
        useEffect(() => {
            window.scrollTo(0, 0);
            console.log('scroll to top');
        }, [location.pathname]);
        return <Component {...(props as Props)} />;
    };
};

export default withRouter;
